<?php

namespace App\Http\Requests\User\Personal;

use App\Models\System\Setting;
use App\Exceptions\GeneralException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Foundation\Http\FormRequest;

/**
 * 补全用户信息请求
 *
 * Date: 2018/5/31
 * @author George
 * @package App\Http\Requests\User\Personal
 */
class ModifyProfile extends FormRequest
{
	protected $rules = [];

	/**
	 * Date: 27/04/2018
	 * @author George
	 * @return bool
	 */
    public function authorize()
    {
        return true;
    }

	/**
	 * 获取规则
	 *
	 * Date: 27/04/2018
	 * @author George
	 * @return array
	 * @throws GeneralException
	 */
    public function rules()
    {
		if (! $this->get('company_id')) {
			throw new GeneralException('请选择公司', 422);
		}

		// 获取公司的注册设置
		return Cache::remember("companies:{$this->company_id}:rules", 360, function () {
			$result = Setting::query()->select(['company_id', 'register'])->where('company_id', $this->company_id)->first()->toArray();
			return array_get($result, 'register', config('system.register'));
		});
    }

	/**
	 * 定义错误消息
	 *
	 * Date: 2018/5/31
	 * @author George
	 * @return array
	 */
	public function messages()
	{
		return [
			'stature.required' => '请输入身高',
			'weight.required' => '请输入体重',
			'education.required' => '请输入学历',
			'address.required' => '请输入地址',
			'marital.required' => '请选择婚姻状态',
			'urgency_name.required' => '请输入紧急联系人姓名',
			'urgency_mobile.required' => '请输入紧急联系人联系方式',
			'urgency_relation.required' => '请输入与联系人的关系',
			'trade.required' => '请选择行业信息',
			'skill.required' => '请选择技能',
			'channel.required' => '请选择应聘渠道',
		];
    }
}
